package top.maof.book.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.vdurmont.emoji.EmojiParser;

import java.io.IOException;

/**
 * jackson反序列化器
 * 将emojiUnicode解码成emojiString
 * 😊  -->  :blush:
 */
public class EmojiDeserialize extends JsonDeserializer<String> {
    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        String emojiUnicode = jsonParser.getText();
        String emojiStr = EmojiParser.parseToAliases(emojiUnicode);
        return emojiStr;
    }
}
